package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Tickets;
import com.share.device.service.TicketsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工单相关接口
 * 提供工单的增删改查等操作
 */
@RestController
@RequestMapping("/tickets")
@Tag(name = "工单接口")
public class TicketsController extends BaseController {
    @Autowired
    private TicketsService ticketsService;

    /**
     * 获取工单列表
     * @param tickets
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "获取工单列表")
    public TableDataInfo list(Tickets tickets){
        startPage();
        List<Tickets> ticketsList = ticketsService.selectTicketsList(tickets);
        return getDataTable(ticketsList);
    }
    /**
     * 获取工单详情
     * @param id
     * @return
     */
    @Operation(summary = "获取工单详情")
    @GetMapping("/{id}")
    public Tickets detail(@PathVariable @Schema(description = "工单ID", required = true) Long id) {
        return ticketsService.getDetailTickets(id);
    }
    /**
     * 添加工单
     * @param tickets
     * @return
     */
    @Operation(summary = "添加工单")
    @RequestMapping
    public AjaxResult add(@Validated @RequestBody Tickets tickets) {
        return toAjax(ticketsService.save(tickets));
    }
    /**
     * 根据柜机编号获取区域运维人员
     */
    @Operation(summary = "根据柜机编号获取区域运维人员")
    @GetMapping("/getAreaOps/{cabinetNo}")
    public AjaxResult getAreaOps(@PathVariable @Schema(description = "柜机编号", required = true) String cabinetNo) {
        return ticketsService.getAreaOps(cabinetNo);
    }
    /**
     * 删除工单
     * @param id
     * @return
     */
    @Operation(summary = "删除工单")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable @Schema(description = "工单ID", required = true) Long id) {
        return toAjax(ticketsService.removeById(id));
    }
    /**
     * 修改工单
     * @param tickets
     * @return
     */
    @Operation(summary = "修改工单")
    @PutMapping
    public AjaxResult edit(@RequestBody Tickets tickets) {
        return toAjax(ticketsService.updateById(tickets));
    }

}
